import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/config/enum/load_state.dart';
import 'package:flutter_changdian_football/widget/default_page/custom_empty.dart';
import 'package:flutter_changdian_football/widget/default_page/custom_error.dart';
import 'package:flutter_changdian_football/widget/default_page/custom_loading.dart';

class LoadStateLayout extends StatelessWidget {
  const LoadStateLayout({
    Key? key,
    this.state = LoadState.loading,
    this.success,
    this.error,
    this.empty,
    this.loading,
    this.network
  }) : super(key: key);

  // 页面状态
  final LoadState state; 
  /// 加载成功
  final Widget? success;
  /// 加载失败
  final Widget? error;
  /// 无数据
  final Widget? empty;
  /// 加载中
  final Widget? loading;
  /// 无网络
  final Widget? network;

  @override
  Widget build(BuildContext context) {
    if (LoadState.success == state) {
      /// 加载成功
      return success ?? const Center(child: Text("加载成功"),);
    } else if (LoadState.error == state) {
      /// 加载失败
      return error ?? const Center(
        child: CustomError(),
      );
    } else if (LoadState.empty == state) {
      /// 无数据
      return empty ?? const Center(
        child: CustomEmpty(),
      );
    } else if (LoadState.loading == state) {
      /// 加载中
      return loading ?? const Center(
        child: CustomLoading(),
      );
    } else if (LoadState.network == state) {
      /// 无网络
      return network ?? const Center(
        child: CustomError(text: '当前暂无可用网络',),
      );
    } else {
      /// 加载错误
      return const Center(
        child: CustomError(),
      );
    }
  }
}